
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2023/05/01
// Design Name:
// Module Name: tm_top
// Project Name: wujian100
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// base ahb addr is 0x4001_0000  none offset
//////////////////////////////////////////////////////////////////////////////////

module tm_top
    (
    input                              tai_clk_i,
    input                              tai_rst_n_i,
    input                 [32 - 1 : 0] tai_haddr_i,
    input                 [4  - 1 : 0] tai_hprot_i,                            //hprot[0]为0，代表是来自tee的访问信号，为1，代表是来自ree的访问信号
    input                 [1  - 1 : 0] tai_hsel_i,
    input                 [3  - 1 : 0] tai_hsize_i,
    input                 [2  - 1 : 0] tai_htrans_i,
    input                 [32 - 1 : 0] tai_hwdata_i,
    input                 [1  - 1 : 0] tai_hwrite_i,

    output                [32 - 1 : 0] tai_hrdata_o,
    output                [1  - 1 : 0] tai_hready_o,
    output                [2  - 1 : 0] tai_hresp_o,
    output                [1  - 1 : 0] tai_t2r_intr_o
    );

wire                      [1  - 1 : 0] t2r_clk_w;
wire                      [1  - 1 : 0] t2r_rst_n_w;
wire                      [1  - 1 : 0] en_box;
wire                      [1  - 1 : 0] write_box;
wire                      [12 - 1 : 0] t2r_addr_w;
wire                      [32 - 1 : 0] t2r_wdat_w;
wire                      [1  - 1 : 0] t2r_rdy_w;
wire                      [32 - 1 : 0] t2r_rdat_w;
wire                      [1  - 1 : 0] t2r_intr_w;

localparam ADDR_W                      = 12;                                   //子模块地址信号位宽，与分配地址空间有关
/************************************/
/*例化子模块                         */
/************************************/

tm_ahb_if
u_tm_ahb_if
    (
    .tai_clk_i                         (tai_clk_i                              ),            
    .tai_rst_n_i                       (tai_rst_n_i                            ),              
    .tai_haddr_i                       (tai_haddr_i                            ),              
    .tai_hprot_i                       (tai_hprot_i                            ),              
    .tai_hsel_i                        (tai_hsel_i                             ),             
    .tai_hsize_i                       (tai_hsize_i                            ),              
    .tai_htrans_i                      (tai_htrans_i                           ),               
    .tai_hwdata_i                      (tai_hwdata_i                           ),               
    .tai_hwrite_i                      (tai_hwrite_i                           ),               
    .tai_hrdata_o                      (tai_hrdata_o                           ),               
    .tai_hready_o                      (tai_hready_o                           ),               
    .tai_hresp_o                       (tai_hresp_o                            ),              
    .tai_t2r_intr_o                    (tai_t2r_intr_o                         ),        

    .t2r_clk_w                         (t2r_clk_w                              ),                  
    .t2r_rst_n_w                       (t2r_rst_n_w                            ),                    
    .en_box                            (en_box                                 ),                   
    .write_box                         (write_box                              ),                   
    .t2r_addr_w                        (t2r_addr_w                             ),                   
    .t2r_wdat_w                        (t2r_wdat_w                             ),                   
    .t2r_rdy_w                         (t2r_rdy_w                              ),                  
    .t2r_rdat_w                        (t2r_rdat_w                             ),                   
    .t2r_intr_w                        (t2r_intr_w                             )                   
    );

spram
   #(
	.ADDR_W                            (ADDR_W                                 )
	)
u_tm_tee2ree_box
    (
    .clk_i                             (t2r_clk_w                              ),
	.rst_n_i                           (t2r_rst_n_w                            ),
    .en_i                              (en_box                                 ),
    .write_i                           (write_box                              ),
	.addr_i                            (t2r_addr_w                             ),
	.wdat_i                            (t2r_wdat_w                             ),
    .rdy_o                             (t2r_rdy_w                              ),
	.rdat_o                            (t2r_rdat_w                             ),
	.intr_o                            (t2r_intr_w                             )    //硬件清除中断标志位，持续一个时钟周期
    );

endmodule

